package com.cl.pile.rule.filter;

import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author chenyitao
 * @date 2021/4/28
 */
public class RegexFilterOperation implements IFilterOperation {
    @Override
    public boolean filterMatch(Object value, String matchValue) {
        try {
            Pattern pattern = Pattern.compile(Optional.ofNullable(matchValue).orElse(""));
            Matcher matcher = pattern.matcher(String.valueOf(value));
            return matcher.find();
        } catch (Exception e) {
            return false;
        }
    }

    @Override
    public String filterName() {
        return "正则匹配";
    }
}
